import uuid

from entity.models import db, LabelRecord


def save_article_labels(label_uuid, article_uuid):
    label_record = LabelRecord()
    label_record.uuid = uuid.uuid4()
    label_record.label_uuid = label_uuid
    label_record.article_uuid = article_uuid
    db.session.add(label_record)
    db.session.commit()
    db.session.close()


def get_label_uuid_by_article_uuid(uuid):
    return db.session.query(LabelRecord).filter(LabelRecord.article_uuid == uuid).all()


def get_label_uuid_by_article_uuid_and_label_uuid(article_uuid, label_uuid):
    return db.session.query(LabelRecord).filter(LabelRecord.article_uuid == article_uuid).filter(
        LabelRecord.label_uuid == label_uuid).first()
